//获取聊天列表
function queryChats(userId){
    fun_loading(!0)
    var urls = baseUrl+"chat/query/"+userId
    http.get(urls,function (err,result){
        if(result.code == 0){
            var datas = result.data;
            datas.forEach(function(e){
                //左侧聊天列表页面
                var html =  '<a class="nav-link" id="chat-'+e.friendId+'-tab" name="'+(e.friendName == null ? e.friendId : e.friendName)+'" data-toggle="pill" href="#chat-'+e.friendId+'"   role="tab" aria-controls="chat-'+e.friendId+'" aria-selected="false">'+
                    '    <div class="media">'+
                    '        <img class="align-self-center rounded-circle" src="assets/images/boy.svg" alt="User Image">'+
                    '            <div class="media-body">'+
                    '                <h5>'+(e.friendName == null ? e.friendId : e.friendName)+'<span class="chat-timing">'+e.createTime+'</span></h5>'+
                    '                <p>'+e.friendRemark+'</p>'+
                    '            </div>'+
                    '    </div>'+
                    '</a>';
                $("#chat-list-tab").append(html);

                //聊天记录页面
                var details = '<div class="tab-pane fade" id="chat-'+e.friendId+'" role="tabpanel" aria-labelledby="chat-'+e.friendId+'-tab">'+
                    '    <div class="empty-screen">'+
                    '        <img src="assets/images/empty-logo.png" class="img-fluid" alt="empty-logo">'+
                    '            <h4 class="my-3">No Conversation Yet.</h4>'+
                    '    </div>'+
                    '</div>';
                $("#chat-listContent").append(details);

                chatList();
            });
        }else{
            layer.msg(result.msg);
        }
        fun_loading(!1)
    });
}

function querySyncUser(){
    fun_loading(!0)
    var urls = serverUrl+"user/syncUser/"+userId
    http.get(urls,function(err,result){
        if(result.code == 0){
            fun_loading(!1);
            layer.msg("同步完成");
            queryChats(userId)
        }else{
            layer.msg(result.msg);
        }
    })
}


function queryChatMessage(userId){
    var urls = serverUrl+"tMessage/query"+userId
    http.get(urls,function(err,result){
        if(result.code == 0){
            var datas = result.data;
            console.log(datas);

        }else{
            layer.msg(result.msg);
        }
    })
}
//触发id的点击事件
function chatList(){
    //点击左侧列表监听事件
    $("#chat-list-tab a").click(function(){
        $(".chat-head h5").html(this.name);
        receiverId = this.id.split("-")[1];
    });
}
